import React, { PropTypes } from 'react';
import { observer } from 'mobx-react';
import store from '../../store';
import { setNow } from '../../store/syncDemo';

@observer
class SyncDemo extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidMount = () => {
        this.timer = setInterval(() => {
            setNow();
        }, 30)
    }
    componentWillUnmount = () => {
        if (this.timer) {
            clearInterval(this.timer);
        }
    }

    render() {
        const syncStore = store.syncStore;

        return (<div>
            <div>现在时间：{syncStore.now}</div>
        </div>);
    }
}

export default SyncDemo;
